json = require "cjson"
json_safe = require "cjson.safe"
util = require "cjson.util"

list = {
	  'name':"xing wenju",
	  'age':"xing wenju",
	  'profession':"xing wenju"
}
strList = json.encode list
print strList
myList =  json.decode strList
print i,v for i,v in pairs myList


data = util.file_load('example.json')
obj = json.decode data
print i,v for i,v in pairs obj

class Car
	new: =>
		@specification = {}
	
	choose:(t)=>
		@specification = t
		print "Dear Customer:"
		print "Your choose #{@specification['brand']}"
		print "---------------------------"
	
	produce:()=>
		print "Start producing car for you"
		print "Here is your specifications:"
		print "---------------------------"
		for k,v in pairs @specification
			print k,v

class Person
	new: =>
		@name = ""
		@age = 0

    grow: () =>
		@age=@age+1

	buy:(v)=>
		print "Hello!"..@name
		print "Wow, you got something" 



class Inventory
	new: =>
		@items = {}

    add_item_by_name: (name) =>
		if @items[name]
			@items[name] += 1
		else
			@items[name] = 1

	add_item_by_index: (t) =>
		index = #@items + 1
		@items[index] = t

-----------------------------------------------------------
-- 2. Controllers
-----------------------------------------------------------

-- Make a car
my_specification = {
	brand:"BMW",
	price:40000,
	length:40,
	heigth:2
}

buycar = ->
	mycar = Car!
	mycar\choose my_specification

	-- Buy the car for inventory
	myinv = Inventory!
	myinv\add_item_by_index mycar
	for i,v in pairs myinv.items
		v\produce!


xingwenju = Person!
xingwenju.name = "xing wenju"
xingwenju\buy "a car"

-----------------------------------------------------------
-- 3. Views
-----------------------------------------------------------
print "Welcome to Car selling system!"
buycar!
